package net.atomarrow.bean;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * service 返回的消息结果
 * @author Michael
 *
 */
public class ServiceResult {
    private boolean success;
    private Object result;
    private boolean warn;//是否有警告信息
    private String msg;
    private Pager pager;
    private transient String[] withParams;
    private transient String[] withoutParams;

    
    public ServiceResult(boolean success,Boolean warn, Object result, String msg) {
    	super();
    	this.success = success;
    	this.warn = warn;
    	this.result = result;
    	this.msg = msg;
    }
    
    public ServiceResult(boolean success, Object result, String msg) {
        super();
        this.success = success;
        this.result = result;
        this.msg = msg;
    }
    public ServiceResult(boolean success, Object result, String msg,Pager pager) {
        this(success,result,msg);
        this.pager=pager;
    }
    public ServiceResult(boolean success, Object result, String msg,String[] withParams,String[] withOutParam) {
        this(success,result,msg);
        this.withParams=withParams;
        this.withoutParams=withOutParam;
    }
    public ServiceResult(boolean success, Object result, String msg,Pager pager,String[] withParams,String[] withOutParam) {
        this(success,result,msg,pager);
        this.withParams=withParams;
        this.withoutParams=withOutParam;
    }
    
    public boolean hasError(){
        return !success;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void transactionRollback() {
//        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    }

    public String[] getWithParams() {
        return withParams;
    }

    public void setWithParams(String[] withParams) {
        this.withParams = withParams;
    }
    public String[] getWithoutParams() {
        return withoutParams;
    }
    public void setWithoutParams(String[] withoutParams) {
        this.withoutParams = withoutParams;
    }

    @JSONField(deserialize=false,serialize=false)
    public boolean isWithMode(){
        return withParams!=null;
    }
    @JSONField(deserialize=false,serialize=false)
    public boolean isWithoutMode(){
        return withoutParams!=null;
    }
    public Pager getPager() {
        return pager;
    }
    public void setPager(Pager pager) {
        this.pager = pager;
    }
	public boolean isWarn() {
		return warn;
	}
	public void setWarn(boolean warn) {
		this.warn = warn;
	}

}
